import binarysearchtree.BinarySearchTree;
import demo1.HashBuck;
import org.omg.PortableInterceptor.ServerRequestInfo;

import javax.swing.tree.TreeNode;
import java.util.*;

public class Test {
    public static void main(String[] args) {
        Stack<Integer> stack = new Stack<>();
        System.out.println();
        System.out.println();
    }
    public static void main7(String[] args) {
        LinkedList list = new LinkedList();
        list.addFirst(1);
        list.addFirst(2);
        list.addFirst(3);
        list.addFirst(4);
        list.display();

        list.addLast(1);
        list.addLast(2);
        list.addLast(3);
        list.addLast(4);
        list.display();

        list.remove(4);
        list.display();
        list.remove(1);
        list.display();
        System.out.println(list.size());

        list.addIndex(0,1);
        list.addFirst(1);
        list.display();
        list.removeAllKey(1);
        list.display();
        list.clear();
        System.out.println(list.size());
        list.addFirst(1);
        list.display();
    }
    public static void main6(String[] args) {
        SingleLinkedList list = new SingleLinkedList();
        list.addFirst(1);
        list.addFirst(2);
        list.addFirst(3);
        list.addFirst(4);
        list.display();
        System.out.println(list.size());

        list.addLast(1);
        list.addLast(2);
        list.addLast(3);
        list.addLast(4);
        list.display();
        System.out.println(list.size());

        list.addIndex(0,0);
        list.addIndex(5,0);
        list.display();
        list.remove(4);
        list.display();

        list.removeAllKey(0);
        list.display();

        list.removeAllKey(1);
        list.display();
        System.out.println(list.size());
    }
    public static void main5(String[] args) {
        MyArrayList myArrayList = new MyArrayList();
        myArrayList.add(10);
        myArrayList.add(5);
        myArrayList.add(6);
        myArrayList.display();

        myArrayList.add(1,1);
        myArrayList.display();

        myArrayList.add(5);
        myArrayList.display();
    }
    public static void main4(String[] args) {
        HashBuck hashBuck = new HashBuck();
        hashBuck.put(1,11);
        hashBuck.put(2,22);
        hashBuck.put(9,99);
        hashBuck.put(5,99);
        hashBuck.put(4,99);
        hashBuck.put(7,99);
        hashBuck.put(3,99);
        hashBuck.put(8,99);
        hashBuck.put(10,99);

        System.out.println(hashBuck.get(9));
    }
    public static void main3(String[] args) {
        Set<String> set = new TreeSet<>();
        set.add("hello");
        set.add("sunny");
        //因为TreeSet底层是一个TreeMap,所以不能有重复的

        System.out.println(set);

        Iterator<String> it = set.iterator();//迭代器遍历
        while (it.hasNext()) {
            System.out.println(it.next());
        }
        System.out.println();
        System.out.println();
        System.out.println();
        System.out.println();
    }
    public static void main2(String[] args) {
        TreeMap<String, Integer> map1 = new TreeMap<>();//时间复杂度O(logN)
        map1.put("sunny", 3);//相当于这个单词出现了3次
        map1.put("the", 5);
        map1.put("the", 7);//再添加一次相同的键则会覆盖之前的数据

        Integer val = map1.get("the2");//获取对应的值
        System.out.println(val);

        Integer val2 = map1.getOrDefault("the2", 999);//因为没有这个key返回默认值
        System.out.println(val2);

        Set<String> set = map1.keySet();//获取所有的key
        System.out.println(set);

        Set<Map.Entry<String, Integer>> entrySet = map1.entrySet();

        for (Map.Entry<String, Integer> entry : entrySet) {
            System.out.println("key: " + entry.getKey() + " value: " + entry.getValue());
        }



        Map<String, Integer> map2 = new HashMap<>();//时间复杂度O(1) 哈希表 -> 数组 + 链表 + 红黑树 组成
    }
    public static void main1(String[] args) {
        BinarySearchTree binarySearchTree = new BinarySearchTree();
        //给一个数组
        int[] arr = {5,12,3,2,11,15};
        for (int i = 0; i < arr.length; i++) {
            binarySearchTree.insert(arr[i]);
        }

        System.out.println(binarySearchTree.search(11));
        System.out.println(binarySearchTree.search(111));
        binarySearchTree.remove(12);
        System.out.println();
    }
}
